package com.neuedu.his.controller;

import java.io.Serializable;

public class ResultWrapper<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code;       // 状态码，200成功，500失败等
    private String message; // 返回信息
    private T data;         // 返回数据

    public ResultWrapper() {}

    public ResultWrapper(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 成功有数据返回
    public static <T> ResultWrapper<T> success(T data) {
        return new ResultWrapper<>(200, "success", data);
    }

    // 仅返回成功消息
    public static <T> ResultWrapper<T> success(String message) {
        return new ResultWrapper<>(200, message, null);
    }

    // 失败返回消息
    public static <T> ResultWrapper<T> fail(String message) {
        return new ResultWrapper<>(500, message, null);
    }

    // getter 和 setter

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
